package org.linlinjava.litemall.db.domain;

import lombok.Data;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;

@Data
public class LitemallGoodsAccessory {
    public static final Boolean IS_DELETED = Deleted.IS_DELETED.value();

    public static final Boolean NOT_DELETED = Deleted.NOT_DELETED.value();

    private Integer id;

    private Integer goodsId;

    private Integer merchandiseId;

    private String groupName;

    private String groupNameEn;

    private String name;

    private Integer number;

    private BigDecimal price;

    private BigDecimal consumeRatio;

    private Integer costType;

    private LocalDateTime addTime;

    private Integer addUserId;

    private Boolean deleted;

    private Integer accessoryGroupId;

    private String accessoryGroupName;

    private Double muchContent;

    private Double fewContent;

    private BigDecimal dosage;


    @Override
    public boolean equals(Object that) {
        if (this == that) {
            return true;
        }
        if (that == null) {
            return false;
        }
        if (getClass() != that.getClass()) {
            return false;
        }
        LitemallGoodsAccessory other = (LitemallGoodsAccessory) that;
        return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
            && (this.getGoodsId() == null ? other.getGoodsId() == null : this.getGoodsId().equals(other.getGoodsId()))
            && (this.getMerchandiseId() == null ? other.getMerchandiseId() == null : this.getMerchandiseId().equals(other.getMerchandiseId()))
            && (this.getGroupName() == null ? other.getGroupName() == null : this.getGroupName().equals(other.getGroupName()))
            && (this.getGroupNameEn() == null ? other.getGroupNameEn() == null : this.getGroupNameEn().equals(other.getGroupNameEn()))
            && (this.getName() == null ? other.getName() == null : this.getName().equals(other.getName()))
            && (this.getNumber() == null ? other.getNumber() == null : this.getNumber().equals(other.getNumber()))
            && (this.getPrice() == null ? other.getPrice() == null : this.getPrice().equals(other.getPrice()))
            && (this.getConsumeRatio() == null ? other.getConsumeRatio() == null : this.getConsumeRatio().equals(other.getConsumeRatio()))
            && (this.getCostType() == null ? other.getCostType() == null : this.getCostType().equals(other.getCostType()))
            && (this.getAddTime() == null ? other.getAddTime() == null : this.getAddTime().equals(other.getAddTime()))
            && (this.getAddUserId() == null ? other.getAddUserId() == null : this.getAddUserId().equals(other.getAddUserId()))
            && (this.getDeleted() == null ? other.getDeleted() == null : this.getDeleted().equals(other.getDeleted()))
            && (this.getAccessoryGroupId() == null ? other.getAccessoryGroupId() == null : this.getAccessoryGroupId().equals(other.getAccessoryGroupId()))
            && (this.getAccessoryGroupName() == null ? other.getAccessoryGroupName() == null : this.getAccessoryGroupName().equals(other.getAccessoryGroupName()))
            && (this.getMuchContent() == null ? other.getMuchContent() == null : this.getMuchContent().equals(other.getMuchContent()))
            && (this.getFewContent() == null ? other.getFewContent() == null : this.getFewContent().equals(other.getFewContent()));
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
        result = prime * result + ((getGoodsId() == null) ? 0 : getGoodsId().hashCode());
        result = prime * result + ((getMerchandiseId() == null) ? 0 : getMerchandiseId().hashCode());
        result = prime * result + ((getGroupName() == null) ? 0 : getGroupName().hashCode());
        result = prime * result + ((getGroupNameEn() == null) ? 0 : getGroupNameEn().hashCode());
        result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
        result = prime * result + ((getNumber() == null) ? 0 : getNumber().hashCode());
        result = prime * result + ((getPrice() == null) ? 0 : getPrice().hashCode());
        result = prime * result + ((getConsumeRatio() == null) ? 0 : getConsumeRatio().hashCode());
        result = prime * result + ((getCostType() == null) ? 0 : getCostType().hashCode());
        result = prime * result + ((getAddTime() == null) ? 0 : getAddTime().hashCode());
        result = prime * result + ((getAddUserId() == null) ? 0 : getAddUserId().hashCode());
        result = prime * result + ((getDeleted() == null) ? 0 : getDeleted().hashCode());
        result = prime * result + ((getAccessoryGroupId() == null) ? 0 : getAccessoryGroupId().hashCode());
        result = prime * result + ((getAccessoryGroupName() == null) ? 0 : getAccessoryGroupName().hashCode());
        result = prime * result + ((getMuchContent() == null) ? 0 : getMuchContent().hashCode());
        result = prime * result + ((getFewContent() == null) ? 0 : getFewContent().hashCode());
        return result;
    }

    public enum Deleted {
        NOT_DELETED(new Boolean("0"), "未删除"),
        IS_DELETED(new Boolean("1"), "已删除");

        private final Boolean value;

        private final String name;

        Deleted(Boolean value, String name) {
            this.value = value;
            this.name = name;
        }

        public Boolean getValue() {
            return this.value;
        }

        public Boolean value() {
            return this.value;
        }

        public String getName() {
            return this.name;
        }
    }

    public enum Column {
        id("id", "id", "INTEGER", false),
        goodsId("goods_id", "goodsId", "INTEGER", false),
        merchandiseId("merchandise_id", "merchandiseId", "INTEGER", false),
        groupName("group_name", "groupName", "VARCHAR", false),
        groupNameEn("group_name_en", "groupNameEn", "VARCHAR", false),
        name("name", "name", "VARCHAR", true),
        number("number", "number", "INTEGER", true),
        price("price", "price", "DECIMAL", false),
        consumeRatio("consume_ratio", "consumeRatio", "DECIMAL", false),
        costType("cost_type", "costType", "INTEGER", false),
        addTime("add_time", "addTime", "TIMESTAMP", false),
        addUserId("add_user_id", "addUserId", "INTEGER", false),
        deleted("deleted", "deleted", "BIT", false),
        accessoryGroupId("accessory_group_id", "accessoryGroupId", "INTEGER", false),
        accessoryGroupName("accessory_group_name", "accessoryGroupName", "VARCHAR", false),
        muchContent("much_content", "muchContent", "INTEGER", false),
        fewContent("few_content", "fewContent", "INTEGER", false);

        private static final String BEGINNING_DELIMITER = "`";

        private static final String ENDING_DELIMITER = "`";

        private final String column;

        private final boolean isColumnNameDelimited;

        private final String javaProperty;

        private final String jdbcType;

        public String value() {
            return this.column;
        }

        public String getValue() {
            return this.column;
        }

        public String getJavaProperty() {
            return this.javaProperty;
        }

        public String getJdbcType() {
            return this.jdbcType;
        }

        Column(String column, String javaProperty, String jdbcType, boolean isColumnNameDelimited) {
            this.column = column;
            this.javaProperty = javaProperty;
            this.jdbcType = jdbcType;
            this.isColumnNameDelimited = isColumnNameDelimited;
        }

        public String desc() {
            return this.getEscapedColumnName() + " DESC";
        }

        public String asc() {
            return this.getEscapedColumnName() + " ASC";
        }

        public static Column[] excludes(Column ... excludes) {
            ArrayList<Column> columns = new ArrayList<>(Arrays.asList(Column.values()));
            if (excludes != null && excludes.length > 0) {
                columns.removeAll(new ArrayList<>(Arrays.asList(excludes)));
            }
            return columns.toArray(new Column[]{});
        }

        public String getEscapedColumnName() {
            if (this.isColumnNameDelimited) {
                return new StringBuilder().append(BEGINNING_DELIMITER).append(this.column).append(ENDING_DELIMITER).toString();
            } else {
                return this.column;
            }
        }

        public String getAliasedEscapedColumnName() {
            return this.getEscapedColumnName();
        }
    }
}